package angry.courses.servlets;

import javax.naming.InitialContext;

import java.util.List;

import angry.courses.beans.Course;
import angry.courses.beans.CourseBean;
import angry.courses.entities.CourseEntity;

public class CourseDelegate {

	private Course courseBean;
  
	public CourseDelegate() {
		try {
			InitialContext ctx = new InitialContext();
			courseBean = (Course) ctx.lookup("angry.courses.beans.CourseBean");
//			java.lang.Object ejbHome = ctx.lookup("beans");
//			courseBean = (Course) javax.rmi.PortableRemoteObject.narrow(ejbHome, CourseBean.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public CourseEntity createCourse(String name, int year, int sem, String prof) {
		return courseBean.createCourse(name, year, sem, prof);
	}
	
	public List<CourseEntity> getCourses(int year, int semester) {
		return courseBean.getCourses(year, semester);
	}
	
	public CourseEntity getCourse(String name) {
		return courseBean.getCourse(name);
	}
	
	public List<String> getCourseNamesForSemester(int sem) {
		return courseBean.getCourseNamesForSemester(sem);
	}
	
	public List<String> getCourseNames() {
		return courseBean.getCourseNames();
	}
	
	public void removeCourse(CourseEntity course) {
		courseBean.removeCourse(course);
	}
}
